﻿<Window x:Class="S7_DMCToolbox.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:DMC.UI="clr-namespace:DMC.UI;assembly=DMC.UI"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:this="clr-namespace:S7_DMCToolbox"
        Height="642" 
        Title="DMC S7 Toolbox" 
        Width="702" Icon="/S7_DMCToolbox;component/DMC%20Siemens%20Icon.ico">
    <Window.Resources>
        <this:S7_ViewModel x:Key="VM"/>
        <this:SeverityToImageConverter x:Key="SeverityToImageConverter" />
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
        <this:SimilarityToColorConverter x:Key="SimilarityToColorConverter" />
        <Style TargetType="TextBlock" x:Key="TextBlockHeader1Style">
            <Setter Property="VerticalAlignment" Value="Center" />
            <Setter Property="Foreground" Value="Black" />
            <Setter Property="FontSize" Value="14" />
            <Setter Property="FontWeight" Value="Bold" />
            <Setter Property="Margin" Value="5,0" />
        </Style>

        <!--<Style TargetType="GroupBox">
            <Setter Property="HeaderTemplate">
                <Setter.Value>
                    <DataTemplate DataType="Header" >
                        <TextBlock Text="{Binding}" Style="{StaticResource TextBlockHeader1Style}" />
                    </DataTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="Margin" Value="5" />
            <Setter Property="BorderThickness" Value="2" />
        </Style>-->
    </Window.Resources>

    <Grid DataContext="{Binding Source={StaticResource VM}}">
        <Grid >
            <DockPanel>
             
                <GroupBox DockPanel.Dock="Top" Header="Project Path" >
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="25" />
                            <ColumnDefinition Width="4*" />

                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition />
                        </Grid.RowDefinitions>
                        <Label Grid.Row="0" Grid.Column="0" FontWeight="Bold">Select Project:</Label>
                        <Button Grid.Row="0" Grid.Column="1" Margin="2" Content="..." Command="{Binding Path=BrowseCmd}" CommandParameter=""/>
                        <TextBlock Grid.Row="0" Grid.Column="2" Margin="5" VerticalAlignment="Center" Text="{Binding ProjectPath}" />
                    </Grid>
                </GroupBox>
                <Grid DockPanel.Dock="Left">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    
                    <DockPanel Grid.Column="1">
                        <Grid DockPanel.Dock="Bottom" >
                            <DockPanel Height="50" >
                                <Button DockPanel.Dock="Right" Content="Cancel" Command="{Binding CancelCmd}" Width="75" Margin="5" />
                                <Button DockPanel.Dock="Right" Content="AlarmWorx" Command="{Binding GetAlarmWorxInfoCmd}" Width="75" Margin="5" />
                                <Button DockPanel.Dock="Right" Content="Kepware" Command="{Binding ExportKepwareCmd}" Width="75" Margin="5" />
                                
                                
                                    <Viewbox Height="35" Width="35" >
                                    <DMC.UI:ProgressWheel Visibility="{Binding IsBusy, Converter={StaticResource BooleanToVisibilityConverter}}" Margin="5">
                                        <!--<DMC.UI:ProgressWheel.RenderTransform>
                                            <ScaleTransform ScaleX=".2" ScaleY=".2"></ScaleTransform>
                                        </DMC.UI:ProgressWheel.RenderTransform>-->
                                    </DMC.UI:ProgressWheel>
                                    </Viewbox>

                                <ProgressBar Grid.Column="0" Value="{Binding ProgressBarCurrent}" Maximum="{Binding ProgressBarMax}" Visibility="{Binding IsBusy, Converter={StaticResource BooleanToVisibilityConverter}}" Margin="5"/>
                                
                            </DockPanel>
                        </Grid>
                        
                        <!--<GroupBox DockPanel.Dock="Right" Header="Messages">-->
                            <Grid>
                            <Grid.Resources>
                                <Style TargetType="ScrollViewer">
                                    <Setter Property="this:ScrollSynchronizer.ScrollGroup" Value="Group1" />
                                </Style>
                           
                            </Grid.Resources>

                            <Grid.RowDefinitions>
                                    <RowDefinition/>
                                    <RowDefinition Height="100"/>
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    
                                    
                                </Grid.ColumnDefinitions>
                            <GroupBox Name="groupBox"  DockPanel.Dock="Right" Header="Blocks">
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="*"/>
                                        <RowDefinition Height="40" ></RowDefinition>
                                    </Grid.RowDefinitions>
                                    <DataGrid  Grid.Row="0" DockPanel.Dock="Top"  BorderBrush="#DDDDDD"  Name="dataGrid" HorizontalGridLinesBrush="#DDDDDD" VerticalGridLinesBrush="#DDDDDD" IsReadOnly="True"  Grid.Column="0" AutoGenerateColumns="False" ItemsSource="{Binding AllBlocks}" Margin="5"  SelectedItem="{Binding SelectedBlock}" SelectionMode="Extended">
                                    <DataGrid.Resources>
                                        <Style TargetType="DataGridCell">
                                            <Style.Triggers>
                                                <!-- Highlight selected rows -->
                                                <Trigger Property="IsSelected" Value="True">
                                                    <Setter Property="Background" Value="Lavender" />
                                                    <Setter Property="BorderBrush" Value="Lavender" />
                                                    <Setter Property="Foreground" Value="Black" />
                                                </Trigger>
                                            </Style.Triggers>
                                            <Setter Property="BorderThickness" Value="0,0,1,1"/>
                                            <Setter Property="BorderBrush" Value="#DDDDDD"/>
                                            <!-- Add some padding around the contents of a cell -->
                                            <Setter Property="Padding" Value="4,3,4,3" />
                                            <Setter Property="Template">
                                                <Setter.Value>
                                                    <ControlTemplate TargetType="DataGridCell">
                                                        <Border Padding="{TemplateBinding Padding}" 
                                Background="{TemplateBinding Background}">
                                                            <ContentPresenter />
                                                        </Border>
                                                    </ControlTemplate>
                                                </Setter.Value>
                                            </Setter>

                                        </Style>
                                    </DataGrid.Resources>
                                    <DataGrid.Columns>
                                        <DataGridTextColumn Width="1.3*" Header="Name" Binding="{Binding Value.Name}"/>
                                        <DataGridTextColumn Width="1*" Header="Size" Binding="{Binding Value.Size}"/>
                                        <DataGridTemplateColumn Width="5*" Header="Symbol"  >
                                            <DataGridTemplateColumn.CellTemplate>
                                                <DataTemplate>
                                                    <TextBlock Text="{Binding Value.SymbolicName}" ToolTipService.ToolTip="{Binding Key}" />
                                                </DataTemplate>
                                            </DataGridTemplateColumn.CellTemplate>
                                        </DataGridTemplateColumn>
                                        <DataGridTextColumn Width="4*" Header="Modified" Binding="{Binding Value.Modified}"/>
                                        </DataGrid.Columns>
                                </DataGrid>
                                    <Grid Grid.Row="1" DockPanel.Dock="Bottom" Width="250" Height="30" VerticalAlignment="Bottom" HorizontalAlignment="Left">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto"/>
                                            <ColumnDefinition Width="Auto"/>
                                            <ColumnDefinition Width="Auto"/>
                                            <ColumnDefinition Width="Auto"/>
                                            <ColumnDefinition Width="Auto"/>
                                            <ColumnDefinition Width="Auto"/>
                                            <ColumnDefinition Width="Auto"/>
                                            <ColumnDefinition Width="Auto"/>
                                        </Grid.ColumnDefinitions>
                                 
                                        <ToggleButton Grid.Column="1" IsChecked="{Binding fbFilter}"  HorizontalAlignment="Left" VerticalAlignment="Top" Width="30" Height="30">
                                            <StackPanel>
                                                <Label FontSize="11" >fb</Label>
                                            </StackPanel>
                                        </ToggleButton>
                                        <ToggleButton Grid.Column="2" IsChecked="{Binding fcFilter}"  HorizontalAlignment="Left" VerticalAlignment="Top" Width="30" Height="30">
                                            <StackPanel>
                                                <Label FontSize="11" >fc</Label>
                                            </StackPanel>
                                        </ToggleButton>
                                        <ToggleButton Grid.Column="3" IsChecked="{Binding obFilter}"  HorizontalAlignment="Left" VerticalAlignment="Top" Width="30" Height="30">
                                            <StackPanel>
                                                <Label FontSize="11" >ob</Label>
                                            </StackPanel>
                                        </ToggleButton>
                                        <ToggleButton Grid.Column="4" IsChecked="{Binding udtFilter}"  HorizontalAlignment="Left" VerticalAlignment="Top" Width="40" Height="30">
                                            <StackPanel>
                                                <Label FontSize="11" >udt</Label>
                                            </StackPanel>
                                        </ToggleButton>
                                        <ToggleButton Grid.Column="5" IsChecked="{Binding dbFilter}"  HorizontalAlignment="Left" VerticalAlignment="Top" Width="30" Height="30">
                                            <StackPanel>
                                                <Label FontSize="11" >db</Label>
                                            </StackPanel>
                                        </ToggleButton>
                                        <ToggleButton Grid.Column="6" IsChecked="{Binding vatFilter}"  HorizontalAlignment="Left" VerticalAlignment="Top" Width="30" Height="30">
                                            <StackPanel>
                                                <Label FontSize="11" >vat</Label>
                                            </StackPanel>
                                        </ToggleButton>
                                        <ToggleButton Grid.Column="7" IsChecked="{Binding recentFilter}"  HorizontalAlignment="Left" VerticalAlignment="Top" Width="60" Height="30">
                                            <StackPanel>
                                                <Label FontSize="11" >recent</Label>
                                            </StackPanel>
                                        </ToggleButton>
                                    </Grid>
                                </Grid>
                            </GroupBox>
                            
                                <ListView ItemsSource="{Binding LogModel}" Margin="5" Grid.ColumnSpan="3" Grid.Row="1">
                                    
                                    <ListView.ItemTemplate>
                                        <DataTemplate>
                                            <Grid>
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="Auto" />
                                                    <ColumnDefinition Width="Auto" />
                                                    <ColumnDefinition Width="*" />
                                                </Grid.ColumnDefinitions>
                                                <Image Grid.Column="0" Height="16" Width="16" Source="{Binding Path=LogSeverity, Converter={StaticResource SeverityToImageConverter}}" Margin="5,1" />
                                                <TextBlock Grid.Column="1" Text="{Binding Timestamp}" VerticalAlignment="Center" Margin="5,1" />
                                                <TextBlock Grid.Column="2" Text="{Binding Message}" VerticalAlignment="Center" Margin="5,1" />
                                            </Grid>
                                        </DataTemplate>
                                    </ListView.ItemTemplate>
                                </ListView>
                        </Grid>
                    </DockPanel>
                </Grid>
                <Popup IsOpen="True">
                    
                </Popup>
            </DockPanel>
        </Grid>
        
    </Grid>
</Window>
